home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / checkbox / plugins / category_prompt.py < prev    next >
Encoding:
Python Source  |  2009-04-27  |  2.4 KB  |  74 lines

  1. #
  2. # This file is part of Checkbox.
  3. #
  4. # Copyright 2008 Canonical Ltd.
  5. #
  6. # Checkbox is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Checkbox is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. from gettext import gettext as _
  20.  
  21. from checkbox.properties import String
  22. from checkbox.plugin import Plugin
  23.  
  24.  
  25. class CategoryPrompt(Plugin):
  26.  
  27.     # Category of the system: desktop, laptop or server
  28.     category = String(required=False)
  29.  
  30.     def register(self, manager):
  31.         super(CategoryPrompt, self).register(manager)
  32.  
  33.         for (rt, rh) in [
  34.              ("gather-persist", self.gather_persist),
  35.              ("prompt-category", self.prompt_category)]:
  36.             self._manager.reactor.call_on(rt, rh)
  37.  
  38.     def gather_persist(self, persist):
  39.         self.persist = persist.root_at("category_prompt")
  40.  
  41.     def prompt_category(self, interface):
  42.         category = self.persist.get("category") or self.category
  43.         registry = self._manager.registry
  44.  
  45.         # Try to determine category from HAL formfactor
  46.         if not category:
  47.             formfactor = registry.hal.computer.system.formfactor
  48.             if formfactor is not "unknown":
  49.                 category = formfactor
  50.  
  51.         # Try to determine category from dpkg architecture
  52.         if not category:
  53.             architecture = registry.dpkg.architecture
  54.             if architecture is "sparc":
  55.                 category = "server"
  56.  
  57.         # Try to determine category from kernel version
  58.         if not category:
  59.             version = registry.hal.computer.system.kernel.version
  60.             if str(version).endswith("-server"):
  61.                 category = "server"
  62.  
  63.         # Prompt for the category explicitly
  64.         if not category:
  65.             category = interface.show_category(_("Category"),
  66.                 _("Please select the category of your system."),
  67.                 category)
  68.  
  69.         self.persist.set("category", category)
  70.         self._manager.reactor.fire("report-category", category)
  71.  
  72.  
  73. factory = CategoryPrompt
  74.